package com.example.administrator.newjiajiesong.main.activity;

import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.administrator.newjiajiesong.R;
import com.example.administrator.newjiajiesong.base.BaseTreeActivity;
import com.example.administrator.newjiajiesong.main.activity.LoginActivity;
import com.example.administrator.newjiajiesong.main.activity.mvp.contract.RegisterContract;
import com.example.administrator.newjiajiesong.main.activity.mvp.presenter.RegisterPresenterImpl;
import com.example.administrator.newjiajiesong.widget.ClearEditText;


/**
 * RegisterActivity
 * (๑• . •๑)
 * 类描述:注册页面
 * Created by LeiXiaoXing on 2017/3/14 14:46
 */

public class RegisterActivity extends BaseTreeActivity<RegisterContract.View, RegisterPresenterImpl> implements RegisterContract.View {

    private Button mBtnsendcode;
    private EditText mEtcode;
    private ClearEditText mCetRefereeStudentId;
    private ClearEditText mCetsurepassword;
    private ClearEditText mCetpassword;
    private ClearEditText mCetphone;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_register;
    }

    @Override
    protected void initView() {
        initStyle(true);

        mBtnsendcode = (Button) findViewById(R.id.btn_send_code);
        mEtcode = (EditText) findViewById(R.id.et_code);
        mCetRefereeStudentId = (ClearEditText) findViewById(R.id.cet_RefereeStudentId);
        mCetsurepassword = (ClearEditText) findViewById(R.id.cet_sure_password);
        mCetpassword = (ClearEditText) findViewById(R.id.cet_password);
        mCetphone = (ClearEditText) findViewById(R.id.cet_phone);
    }

    @Override
    protected void initData() {
        //默认可用学号
//        mCetRefereeStudentId.setText("919331538");
    }

    @Override
    protected void initEvent() {

        findViewById(R.id.tv_go_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //已有账号去登录
                startActivity(LoginActivity.class);
            }
        });
        mBtnsendcode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送验证码
                getPresenter().sendCode();
            }
        });
        findViewById(R.id.btn_register).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //注册
                getPresenter().register();
            }
        });
    }

    @NonNull
    @Override
    public RegisterPresenterImpl createPresenter() {
        return new RegisterPresenterImpl();
    }

    @Override
    public String getMobile() {
        return mCetphone.getText().toString();
    }

    @Override
    public String getPassWord() {
        return mCetpassword.getText().toString();
    }

    @Override
    public String getSurePassWord() {
        return mCetsurepassword.getText().toString();
    }

    @Override
    public String getStdNo() {
        return mCetRefereeStudentId.getText().toString();
    }

    @Override
    public String getCode() {
        return mEtcode.getText().toString();
    }

    @Override
    public void setCodeBtnEnable(boolean enable) {
        mBtnsendcode.setEnabled(enable);
    }

    @Override
    public void setCodeBtnText(String msg) {
        mBtnsendcode.setText(msg);
    }
}
